package com.example.demo.niuke;

/**
 * @Description: 先输入键值对的个数 然后输入成对的index和value值，以空格隔开
 * 输出合并后的键值对（多行）
 * @Author: LLL
 * @Date: 2020-03-17 21:44
 **/
/*public class Main4 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 键值对个数
        int num = sc.nextInt();
        Stack<Integer> indexStack = new Stack<>();
        Stack<Integer> numStack = new Stack<>();
        for (int i = 0; i < num; i++) {
            if (sc.hasNextLine()) {
                String s = sc.nextLine();
                indexStack.push(Integer.parseInt(s.split(" ")[0]));
                numStack.push(Integer.parseInt(s.split(" ")[1]));
            }
        }
    }
}*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main4 {
    public static void main(String[] args) throws IOException {
        BufferedReader bff = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(bff.readLine());
        int temp = n;
        String str, s[];
        int[] arr = new int[n];
        while (temp > 0) {
            s = bff.readLine().split(" ");
            arr[Integer.parseInt(s[0])] += Integer.parseInt(s[1]);
            temp--;
        }
        for (int i = 0; i < n; i++) {
            if (arr[i] != 0) {
                System.out.println("" + i + " " + arr[i]);
            }
        }
    }
}